<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "rbac_role".
 *
 * @property int $id
 * @property string $name 角色名
 */
class RbacRole extends BaseCommonModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'rbac_role';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
        ];
    }

    public function saveRes($resIds){
        $rows = [] ;
        foreach ($resIds as $resId){
            $rows[] = ['role_id' => $this->id , 'resource_id' => $resId ] ;
        }
        return self::batchInsert(RbacRoleResource::tableName(),['role_id','resource_id'],$rows) ;
    }

    public function getRes(){
        return $this->hasMany(RbacRoleResource::className() , ['role_id' => 'id']) ;
    }
}
